package gorails.com;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ViewTripAdapter extends BaseAdapter {
	private  ArrayList<TripListViewOption> values;
	private LayoutInflater inflater;
	private Context context;
	public ViewTripAdapter(Context context, int textViewResourceId, ArrayList<TripListViewOption> values) {
		super();
		this.values= values;
		this.context = context;
		
		
		this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public static class ViewHolder {
		TextView isExpress;
		TextView Title;
		TextView arrivalTime;
		TextView DepartTime;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.view_trip_item, null);
			holder.DepartTime = (TextView) convertView
					.findViewById(R.id.departureTime);
			holder.isExpress = (TextView) convertView
					.findViewById(R.id.isExpress);
			holder.arrivalTime = (TextView) convertView
					.findViewById(R.id.arrivalTime);
			holder.Title = (TextView) convertView.findViewById(R.id.tripTitle);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
        	            
        String ep = values.get(position).getExpress();
        if(ep.equalsIgnoreCase("Yes")){
        	holder.isExpress.setTextColor(Color.GREEN);
        }
        else{
        	holder.isExpress.setTextColor(Color.RED);
        }
        holder.DepartTime.setText(values.get(position).getDeparture());
        holder.isExpress.setText(values.get(position).getExpress());
        holder.arrivalTime.setText(values.get(position).getArrival());
        holder.Title.setText(values.get(position).getTitle());
      
        return convertView;
		
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return values.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return values.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
}